package ca.ets.osgi.uiservice_view;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SpringLayout;

public class View_Confirmation extends Onglets implements Observer{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	

	//private ArrayList<String> list = new ArrayList<String>(); 
	
	
	//message
	private static final String MSG_SUCCESS = "Your conference room was reserved under your name";
	private static final String MSG_FAILURE = "Sorry, your conference room was not reserved";
	private static final String MSG_RESTART = "To reserve another room, close the application and restart the process";
	private static final String MSG_TERMINATED = "Click on Terminer in order to close the application";

	
	//
	private JPanel successPanel;
	private JPanel failurePanel;
	
	
	//JLabel
	private JLabel successLabel = new JLabel(MSG_SUCCESS);
	private JLabel failureLabel = new JLabel(MSG_FAILURE);
	private JLabel restartLabel = new JLabel(MSG_RESTART);  
	private JLabel terminateLabel = new JLabel(MSG_TERMINATED); 
	
	private String userOriginalRequest;
	
	
	public View_Confirmation() {
		super("CONFIRMATION");
		removeAll();
		add(titre);
		setLayout(new FlowLayout(FlowLayout.CENTER, 600, 10));
		dateLabel.setText(Calendar.getInstance().getTime().toString());
	}


	/**
	 * Set the panel according to the result
	 * @param object
	 */
	public void setViewConfirmation(Object object){
		removeAll();
		add(titre);
		setLayout(new FlowLayout(FlowLayout.CENTER, 600, 10));
		ArrayList<String> aList = (ArrayList<String>)object;
		userOriginalRequest = aList.get(0);
		String reponse = aList.get(1);

		if(reponse.equalsIgnoreCase("true")){
			
			add(getSuccessPanel());
			//add(terminer);
		}
		
		else{
			add(getFailurePanel());
		}
		//add(terminer);
	}

	@Override
	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub
		
	}
	
	public JPanel getSuccessPanel(){
		successPanel = new JPanel(new SpringLayout());
		successPanel.setBackground(new Color(0xFFFF99));
		String message = "[";
		/*
		for(String s:list){
			message += s + ", ";
		}
		message += "]";
		*/
		JLabel userInfoLabel = new JLabel(userOriginalRequest);
		
		
		successLabel.setFont(new Font("ARIAL",Font.BOLD,25));
		successLabel.setForeground(Color.GREEN);
		add(successLabel);
		add(dateLabel);
		add(userInfoLabel);
		add(terminateLabel);
		//add(restartLabel);
		add(terminer);
		successPanel.setOpaque(true);
		successPanel.setFont(new Font("Serif",Font.BOLD,5));
		return successPanel;
	}
	
	
	public JPanel getFailurePanel(){
		failurePanel = new JPanel(new SpringLayout());
		failurePanel.setBackground(new Color(0xFFFF99));
		JLabel userInfoLabel = new JLabel(userOriginalRequest);
		failureLabel.setFont(new Font("ARIAL",Font.BOLD,25));
		failureLabel.setForeground(Color.RED);		
		add(dateLabel);
		add(userInfoLabel);
		add(failureLabel);
		add(terminateLabel);
		//add(restartLabel);
		add(terminer);
		failurePanel.setOpaque(true);
		failurePanel.setFont(new Font("Serif",Font.BOLD,15));
		
		return failurePanel;
	}


	
	
	
	

}
